#include <stdio.h>

void bubbleSort(int [], int);

int main()
{
    int arr[] = {10, 8, 7, 9, 1, 5};
    int n = sizeof(arr) / sizeof(arr[0]);
    printf("original array:");
    for (int i = 0; i < n; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
    bubbleSort(arr, n);
    printf("sorted array:");
    for (int i = 0; i < n; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
    return 0;
}

void bubbleSort(int *arr, int n)
{
    int i, j;
    for (i = 0; i < n; i++)
    {
        for (j = n - 1; j > i; j--)
        {
            if (arr[j - 1] > arr[j])
            {
                // swap two element
                int temp = arr[j - 1];
                arr[j - 1] = arr[j];
                arr[j] = temp;
            }
        }
    }
}
